//
// Created by shiminli on 2023/12/28.
//

#ifndef DDOFFICE_NUMBER_H
#define DDOFFICE_NUMBER_H

#include <iostream>
#include <string>
#include <random>
#include "sstream"
#include <regex>
#include <sys/time.h>


class number {
public:
    static int genVerifyCode();

    static std::string intToStr(int number){
        std::stringstream s_tmp;
        s_tmp << number;
        return s_tmp.str();
    }
    static std::string longToStr(long number){
        std::stringstream s_tmp;
        s_tmp << number;
        return s_tmp.str();
    }

    static bool validatePhoneNumberWithRegex(std::string phoneNumber) {
        // 定义中国大陆手机号的正则表达式
        std::regex pattern("^1[3456789]\\d{9}$");
        // 使用正则表达式匹配手机号
        if (std::regex_match(phoneNumber, pattern)) {
            return true;
        } else {
            return false;
        }
    }

    static int daysToSeconds(int days){
        return days * 24 * 60 * 60;
    }

    static std::string timestamp(){
        time_t t = time(nullptr);
        struct tm* now = localtime(&t);
        char str[50];
        struct timeval tv;
        gettimeofday(&tv, NULL);
        strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S", now);
        char buffer[8];
        snprintf(buffer, sizeof(buffer), ".%03d", tv.tv_usec / 1000);
        strcat(str, buffer);
        return str;
    }

};


#endif //DDOFFICE_NUMBER_H
